home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / sofaBookChar.lua < prev    next >
Text File  |  2004-01-29  |  4KB  |  160 lines

  1. -- sofa character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5. --        local sofa = retrieveStateObject("seat");
  6.         local sofa = getStoredOrSender("seat", msg)
  7.  
  8.  
  9.         
  10.         if (not sofa) then
  11.             -- sofa does not exist anymore
  12.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  13.             sendMsg("emoThink", getParent().walkSO);
  14.             exitStateMachine();
  15.         else
  16.             storeStateObject("sofa", sofa);
  17.         end
  18.         
  19.         --freeHands(getParent());
  20.     end )
  21.     
  22.     onExit(function(msg)
  23. --        local sofa = retrieveStateObject("sofa");
  24. --        getParent().unlockActionPoints(sofa);
  25. --        getParent().stopAllActivities(sofa);
  26. --        removeStateObject("sofa");
  27.  
  28.         unlockAll("sofa");        
  29.     end )
  30.     
  31.     -- sit down on sofa
  32.     state("sitDown")
  33.     
  34.         onEnter(function(msg)
  35.                 
  36.             local sofa = retrieveStateObject("sofa");
  37.             local actionPointName = retrieveData("actionPointName");
  38.             
  39.             if (getParent().isActionPointLocked(sofa, actionPointName)) then
  40.                 -- action point is locked
  41.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  42.                 sendMsg("emoThink", getParent().walkSO);
  43.                 freeHands(getParent());
  44.                 exitStateMachine();
  45.             else
  46.                 getParent().lockActionPoint(sofa, actionPointName);
  47.                 setPose("sitdownArmchair");
  48.                 sofa.playSound("Sofa setzen");
  49.             end
  50.             
  51.         end )
  52.     
  53.         onMsg("end", function(msg)
  54.         
  55.             if testCancel() then
  56.                 setState("standUp");
  57.             else
  58.                 setState("readSitting");
  59.             end
  60.  
  61.         end )    
  62.     
  63.         
  64.         
  65.     -- stand up from sofa
  66.     state("readSitting")
  67.     
  68.         onEnter(function(msg)
  69.         
  70.             -- remove closed book
  71.             getParent().detachLeftObjectHolder();    
  72.             local book = retrieveStateObject("book");
  73.             if (book) then book.deleteGameObject(); end
  74.             
  75.             -- load open book
  76.             book = getParent().loadGameObject("StandardGO","bookOpen");
  77.             if (not book) then
  78.                 print("create bookOpen failed");
  79.             end
  80.             storeStateObject("book", book);
  81.             getParent().attachLeftObjectHolder(book);
  82.                                     
  83.             local hands = getParent().handSO;
  84.             hands.stopAnimation();
  85.             
  86.             startAnimation("readBookPage");
  87.             
  88.             local sofa = retrieveStateObject("sofa");
  89.             getParent().startActivity("sit", sofa);
  90.             print(" read activity " .. retrieveData("bookType", " UNKONWN "));
  91.             local readBook = getParent().startActivity("read" .. retrieveData("bookType", "Novel"), book);
  92.             local length, scale = getActivityLength(readBook);
  93.             storeData("length", length);
  94.             
  95.             sendDelayedMsgThis("complete", length);
  96.             sendDelayedMsgThis("turnPage", 3000);
  97.         
  98.             this.actionComplete();
  99.             
  100.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  101.  
  102.         end )    
  103.         
  104.         onMsg("turnPage", function(msg)
  105.             startAnimation("readBookPage");
  106.             sendDelayedMsgThis("turnPage", random(5000, 20000));
  107.         end )
  108.  
  109.         onMsg("end", function(msg)
  110.             if (testCancel()) then
  111.                 setState("standUp");
  112.             end
  113.         end )
  114.  
  115.         onMsg("queue", function(msg)
  116.             setState("standUp");
  117.         end )
  118.  
  119.         onMsg("complete", function(msg)
  120.             setState("standUp");
  121.         end )
  122.         
  123.         onMsg("testCancel", function(msg)
  124.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  125.                 setState("standUp");
  126.             else
  127.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  128.             end
  129.         end )
  130.         
  131.     -- stand up from sofa
  132.     state("standUp")
  133.     
  134.         onEnter(function(msg)
  135.             startAnimation("standupArmchair");
  136.             
  137.             
  138.             local sofa = retrieveStateObject("sofa");
  139.             getParent().stopAllActivities(sofa);
  140.             
  141.             local hands = getParent().handSO;
  142.             hands.stopAnimation();
  143.             
  144.             getParent().detachLeftObjectHolder();    
  145.             local book = retrieveStateObject("book");
  146.             if (book) then 
  147.                 book.deleteGameObject();
  148.                 getParent().stopAllActivities(book);
  149.             end
  150.             
  151.         end )
  152.     
  153.         onMsg("end", function(msg)
  154.             exitStateMachine();
  155.         end )    
  156.     
  157.  
  158.     
  159. endStateMachine()
  160.